package org.rsbot.script.methods;

import java.util.HashSet;
import java.util.Set;
import org.rsbot.client.Client;
import org.rsbot.script.util.Filter;

public class Players extends MethodProvider
{
  public static final Filter<org.rsbot.script.wrappers.RSPlayer> ALL_FILTER = new Filter() {
    public boolean accept(org.rsbot.script.wrappers.RSPlayer paramRSPlayer) {
      return true;
    }
  };

  Players(MethodContext paramMethodContext)
  {
    super(paramMethodContext);
  }

  public org.rsbot.script.wrappers.RSPlayer getMyPlayer()
  {
    return new org.rsbot.script.wrappers.RSPlayer(this.methods, this.methods.client.getMyRSPlayer());
  }

  public org.rsbot.script.wrappers.RSPlayer[] getAll()
  {
    return getAll(ALL_FILTER);
  }

  public org.rsbot.script.wrappers.RSPlayer[] getAll(Filter<org.rsbot.script.wrappers.RSPlayer> paramFilter)
  {
    int[] arrayOfInt1 = this.methods.client.getRSPlayerIndexArray();
    org.rsbot.client.RSPlayer[] arrayOfRSPlayer = this.methods.client.getRSPlayerArray();
    HashSet localHashSet = new HashSet();
    for (int k : arrayOfInt1) {
      if ((k != 0) && (arrayOfRSPlayer[k] != null)) {
        org.rsbot.script.wrappers.RSPlayer localRSPlayer = new org.rsbot.script.wrappers.RSPlayer(this.methods, arrayOfRSPlayer[k]);
        if (paramFilter.accept(localRSPlayer)) {
          localHashSet.add(localRSPlayer);
        }
      }
    }
    return (org.rsbot.script.wrappers.RSPlayer[])localHashSet.toArray(new org.rsbot.script.wrappers.RSPlayer[localHashSet.size()]);
  }

  public org.rsbot.script.wrappers.RSPlayer getNearest(Filter<org.rsbot.script.wrappers.RSPlayer> paramFilter)
  {
    int i = 20;
    Object localObject = null;
    org.rsbot.client.RSPlayer[] arrayOfRSPlayer = this.methods.client.getRSPlayerArray();
    int[] arrayOfInt1 = this.methods.client.getRSPlayerIndexArray();
    for (int m : arrayOfInt1) {
      if (arrayOfRSPlayer[m] == null) {
        continue;
      }
      org.rsbot.script.wrappers.RSPlayer localRSPlayer = new org.rsbot.script.wrappers.RSPlayer(this.methods, arrayOfRSPlayer[m]);
      if (paramFilter.accept(localRSPlayer)) {
        int n = this.methods.calc.distanceTo(localRSPlayer);
        if (n < i) {
          i = n;
          localObject = localRSPlayer;
        }
      }
    }
    return localObject;
  }

  public org.rsbot.script.wrappers.RSPlayer getNearest(String paramString)
  {
    return getNearest(new Filter(paramString) {
      public boolean accept(org.rsbot.script.wrappers.RSPlayer paramRSPlayer) {
        return paramRSPlayer.getName().equals(this.val$name);
      }
    });
  }

  public org.rsbot.script.wrappers.RSPlayer getNearest(int paramInt)
  {
    return getNearest(new Filter(paramInt) {
      public boolean accept(org.rsbot.script.wrappers.RSPlayer paramRSPlayer) {
        return paramRSPlayer.getCombatLevel() == this.val$level;
      }
    });
  }
}